package il.adscan.scan.impl;

import il.adscan.domain.Advertisement;
import il.adscan.domain.AdvertisementFilter;
import il.adscan.exception.ParsingException;

import java.io.IOException;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;

public class ScanRunner implements Callable<List<Advertisement>> {

    private int firstPageToScan;
    private int lastPageToScan;
    private AdScanner adScanner;

    public ScanRunner(int firstPageToScan, int lastPageToScan, AdScanner adScanner) {
        this.firstPageToScan = firstPageToScan;
        this.lastPageToScan = lastPageToScan;
        this.adScanner = adScanner;
    }

    @Override
    public List<Advertisement> call() throws Exception {
        AdvertisementFilter filter = new AdvertisementFilter();
        filter.setFirstPageToScan(firstPageToScan);
        filter.setLastPageToScan(lastPageToScan);
        try {
            return adScanner.scan(filter);
        } catch (IOException e) {
            throw new ParsingException(e.getMessage(), e);
        }
    }
}
